package com.uchedao.seller.ui;

import com.baidu.mobstat.StatService;
import com.uchedao.seller.db.CarDbHelper;
import com.uchedao.seller.http.VolleyUtil;
import com.uchedao.seller.manager.AppInfoManager;
import com.uchedao.seller.manager.UserInfoManager;
import com.uchedao.seller.ui.baidu.BaseActForBaidu;
import com.uchedao.seller.ui.main.IndexFragment;
import com.uchedao.seller.ui.user.LoginFragment;
import com.uchedao.seller.widget.DialogCustomProgress;

/**
 * 主框架
 * Created by zhengxizhen on 15/10/19.
 */
public class MainAct extends BaseActForBaidu {
    private DialogCustomProgress mProDialog;

    @Override
    public String getTAGName() {
        return "MainAct";
    }

    @Override
    public void initFragment() {
        AppInfoManager.syncToken();

        TAG = getTAGName();
        //获取单例网络请求队列
        mQueue = VolleyUtil.getInstance().getRequestQueue();
        // 调试百度统计SDK的Log开关，可以在Eclipse中看到sdk打印的日志，发布时去除调用，或者设置为false
        StatService.setDebugOn(false);
        if (!AppInfoManager.getDB()) {
            AppInfoManager.saveDB(CarDbHelper.importDatabase(this));
        }
        // TODO 进入首个Fragment（登录或者主页）
        if (UserInfoManager.getSTATE()) {
            toFragment(IndexFragment.getInstance(), false, true);
        } else {
            toFragment(LoginFragment.getInstance(), false, true);
        }

    }

    @Override
    public void cancelProgressDialog() {
        // TODO 取消Dialog
        try {
            if (mProDialog != null) {
                mProDialog.dismiss();
                mProDialog = null;
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public boolean isProgressDialogShowing() {
        // TODO Dialog状态
        return mProDialog != null && mProDialog.isShowing();
    }

    @Override
    public void showProgressDialog(String arg0) {
        // TODO 创建并展示Dialog
        if (mProDialog == null) {
            mProDialog = DialogCustomProgress.createDialog(MainAct.this);
            mProDialog.setCanceledOnTouchOutside(false);
        }
        mProDialog.setMessage(arg0);
        if (!mProDialog.isShowing()) {
            mProDialog.show();
        }
    }
}
